//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "UnitedKingdom.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::UnitedKingdom::MarketEnum>^ market) : CCalendar(CUnitedKingdom::typeid)
{
    try
    {
#ifdef HANDLE
        _phUnitedKingdom = NULL;
#endif
        QuantLib::UnitedKingdom::Market _market = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::UnitedKingdom::MarketEnum>::IsSome::get (market) ? (QuantLib::UnitedKingdom::Market)market->Value : QuantLib::UnitedKingdom::Market::Settlement); //10
        _ppUnitedKingdom = new boost::shared_ptr<QuantLib::UnitedKingdom> (new QuantLib::UnitedKingdom ( _market ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (boost::shared_ptr<QuantLib::UnitedKingdom>& childNative, Object^ owner) : CCalendar(CUnitedKingdom::typeid)
{
#ifdef HANDLE
	_phUnitedKingdom = NULL;
#endif
	_ppUnitedKingdom = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
}
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (QuantLib::UnitedKingdom& childNative, Object^ owner) : CCalendar(CUnitedKingdom::typeid)
{
#ifdef HANDLE
	_phUnitedKingdom = NULL;
#endif
	_ppUnitedKingdom = new boost::shared_ptr<QuantLib::UnitedKingdom> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
    _UnitedKingdomOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (CUnitedKingdom^ copy) : CCalendar(CUnitedKingdom::typeid)
{
#ifdef HANDLE
	_phUnitedKingdom = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppUnitedKingdom = new boost::shared_ptr<QuantLib::UnitedKingdom> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
    }
}
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (System::Type^ t) : CCalendar(CUnitedKingdom::typeid)
{
#ifdef HANDLE
	_phUnitedKingdom = NULL;
#endif
	if (!t->IsSubclassOf(CUnitedKingdom::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (QuantLib::Handle<QuantLib::UnitedKingdom>& childNative, Object^ owner)  : CCalendar(CUnitedKingdom::typeid)
{
	_phUnitedKingdom = &childNative;
	_ppUnitedKingdom = &static_cast<boost::shared_ptr<QuantLib::UnitedKingdom>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
    _UnitedKingdomOwner = owner;
}
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (QuantLib::Handle<QuantLib::UnitedKingdom> childNative)  : CCalendar(CUnitedKingdom::typeid)
{
	_phUnitedKingdom = &childNative;
	_ppUnitedKingdom = &static_cast<boost::shared_ptr<QuantLib::UnitedKingdom>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CUnitedKingdom::CUnitedKingdom (QuantLib::UnitedKingdom childNative)  : CCalendar(CUnitedKingdom::typeid)
{
#ifdef HANDLE
	_phUnitedKingdom = NULL;
#endif
	_ppUnitedKingdom = new boost::shared_ptr<QuantLib::UnitedKingdom> (new QuantLib::UnitedKingdom (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppUnitedKingdom));
}
#endif

Cephei::QL::Times::Calendars::CUnitedKingdom::~CUnitedKingdom ()
{
    if (_ppUnitedKingdom != NULL)
    {
	    delete _ppUnitedKingdom;
        _ppUnitedKingdom = NULL;
    }
}
Cephei::QL::Times::Calendars::CUnitedKingdom::!CUnitedKingdom ()
{
    if (_ppUnitedKingdom != NULL)
    {
	    delete _ppUnitedKingdom;
    }
}
QuantLib::UnitedKingdom& Cephei::QL::Times::Calendars::CUnitedKingdom::GetReference ()
{
    if (_ppUnitedKingdom == NULL) throw gcnew NativeNullException ();
	return **_ppUnitedKingdom;
}
boost::shared_ptr<QuantLib::UnitedKingdom>& Cephei::QL::Times::Calendars::CUnitedKingdom::GetShared ()
{
    if (_ppUnitedKingdom == NULL) throw gcnew NativeNullException ();
	return *_ppUnitedKingdom;
}
QuantLib::UnitedKingdom* Cephei::QL::Times::Calendars::CUnitedKingdom::GetPointer ()
{
    if (_ppUnitedKingdom == NULL) throw gcnew NativeNullException ();
	return &**_ppUnitedKingdom;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::UnitedKingdom>& Cephei::QL::Times::Calendars::CUnitedKingdom::GetHandle ()
{
	if (_phUnitedKingdom == NULL)
	{
		_phUnitedKingdom = new Handle<QuantLib::UnitedKingdom> (*_ppUnitedKingdom);
	}
	return *_phUnitedKingdom;
}
#endif
bool Cephei::QL::Times::Calendars::CUnitedKingdom::HasNative () 
{
	return (_ppUnitedKingdom != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::IUnitedKingdom^ Cephei::QL::Times::Calendars::CUnitedKingdom_Factory::Create (Microsoft::FSharp::Core::FSharpOption<QL::Times::Calendars::UnitedKingdom::MarketEnum>^ market)
{
    return gcnew CUnitedKingdom ( market);
}
